package com.bjsxt.shop.goods.pojo;

import java.io.Serializable;
import java.util.Date;

import com.alibaba.fastjson.JSONObject;
import com.bjsxt.shop.common.util.ConstatFinalUtil;
import com.bjsxt.shop.common.util.DateFormatUtil;
import com.bjsxt.shop.users.pojo.AAdmins;

/**
 * 商品的品牌
 * 
 * @author wangshSxt
 *
 */
public class AGoodsBrand implements Serializable
{
	private int id;
	private int adminsId;
	private String name;
	private String website;
	private String logoPath;
	private String content;
	private byte status;
	private Date createTime;
	private Date updateTime;
	private Date pubTime;

	/* 关联关系 */
	private AAdmins admins;

	/* 字符串描述 */
	private String statusStr;

	public int getId()
	{
		return id;
	}

	public void setId(int id)
	{
		this.id = id;
	}

	public int getAdminsId()
	{
		return adminsId;
	}

	public void setAdminsId(int adminsId)
	{
		this.adminsId = adminsId;
	}

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	public String getWebsite()
	{
		return website;
	}

	public void setWebsite(String website)
	{
		this.website = website;
	}

	public String getLogoPath()
	{
		return logoPath;
	}

	public void setLogoPath(String logoPath)
	{
		this.logoPath = logoPath;
	}

	public byte getStatus()
	{
		return status;
	}

	public void setStatus(byte status)
	{
		this.status = status;
	}

	public Date getCreateTime()
	{
		return createTime;
	}

	public void setCreateTime(Date createTime)
	{
		this.createTime = createTime;
	}

	public Date getUpdateTime()
	{
		return updateTime;
	}

	public void setUpdateTime(Date updateTime)
	{
		this.updateTime = updateTime;
	}

	public Date getPubTime()
	{
		return pubTime;
	}

	public void setPubTime(Date pubTime)
	{
		this.pubTime = pubTime;
	}

	public AAdmins getAdmins()
	{
		return admins;
	}

	public void setAdmins(AAdmins admins)
	{
		this.admins = admins;
	}

	public String getStatusStr()
	{
		/*
		 * 状态:0:禁用;1:启用
		 */
		AGoodsBrandEnum[] goodsBrandEnums = AGoodsBrandEnum.values();
		for (int i = 0; i < goodsBrandEnums.length; i++)
		{
			AGoodsBrandEnum goodsBrandEnum = goodsBrandEnums[i];
			if (goodsBrandEnum.toString().startsWith("STATUS_"))
			{
				/* 如果循环的枚举==数据库存储的状态值,赋值枚举指定的字符串 */
				if (goodsBrandEnum.getStatus() == this.status)
				{
					this.statusStr = goodsBrandEnum.getInfo();
					break;
				}
			}
		}
		return statusStr;
	}

	public String getContent()
	{
		return content;
	}

	public void setContent(String content)
	{
		this.content = content;
	}

	/**
	 * 把当前对象变成JSON
	 * @return
	 */
	public JSONObject toJSON()
	{
		DateFormatUtil dateFormatUtil = new DateFormatUtil() ; 
		
		JSONObject resultJSON = new JSONObject() ; 
		resultJSON.put("id", this.getId());
		resultJSON.put("adminsId", this.getAdminsId());
		resultJSON.put("name", this.getName());
		resultJSON.put("website", this.getWebsite());
		/* 路径存储的是nginx的路径+相对路径 */
		resultJSON.put("logoPath", ConstatFinalUtil.CONFIG_JSON.get("websitePath.filePath") + this.getLogoPath());
		resultJSON.put("status", this.getStatus());
		resultJSON.put("statusStr", this.getStatusStr());
		resultJSON.put("createTime", dateFormatUtil.dateTimeStr(this.getCreateTime()));
		resultJSON.put("updateTime", dateFormatUtil.dateTimeStr(this.getUpdateTime()));
		resultJSON.put("pubTime", dateFormatUtil.dateTimeStr(this.getPubTime()));
		
		if(admins != null)
		{
			resultJSON.put("adminsName", this.admins.getTrueName());
			resultJSON.put("admins", admins.toJSON());
		}
		return resultJSON;
	}
}
